﻿<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:s="http://www.codeplex.com/MSSqlSchemaDoc">

  <xsl:param name="DocumentationFile"/>

  <xsl:template match="s:ForeignKeys">

    <tr>
      <td colspan="2" class="descriptionHeader center">
        Foreign Keys:
      </td>
    </tr>

    <tr>
      <td colspan="2">
        <table width="100%">
          <tr class="center tableHeader">
            <td></td>
            <td>IsDisabled</td>
            <td>IsNotForReplication</td>
            <td>IsNotTrusted</td>
            <td>Delete Action</td>
            <td>Update Action</td>
            <td>IsSystemNamed</td>
            <td>Columns</td>
          </tr>

          <xsl:for-each select="s:ForeignKey">
            <xsl:variable name="ForeignKeyName" select="@Name"/>

            <tr class="center">
              <td class="tablePrimaryColumn">
                <xsl:value-of select="$ForeignKeyName"/>
              </td>

              <td>
                <xsl:value-of select="s:IsDisabled"/>
              </td>

              <td>
                <xsl:value-of select="s:IsNotForReplication"/>
              </td>

              <td>
                <xsl:value-of select="s:IsNotTrusted"/>
              </td>

              <td>
                <xsl:value-of select="s:DeleteReferentialActionDescription"/>
              </td>

              <td>
                <xsl:value-of select="s:UpdateReferentialActionDescription"/>
              </td>

              <td>
                <xsl:value-of select="s:IsSystemNamed"/>
              </td>

              <td>
                <table width="100%">

                  <xsl:for-each select="s:Columns/s:ForeignKeyColumnPair">
                    <tr class="center">
                      <td>
                        [<xsl:value-of select="@ReferencingColumnName"/>] References [<xsl:value-of select="@ReferencedColumnName"/>] in [<xsl:value-of select="@ReferencedTableName"/>]
                      </td>
                    </tr>
                  </xsl:for-each>

                </table>
              </td>

            </tr>
            <tr>
              <td colspan="8" class="documentation center">
                <pre>
                  <xsl:value-of select="document($DocumentationFile)/s:TableDocumentation/s:ForeignKeys/s:ForeignKeyDocumentation[@Name=$ForeignKeyName]/s:Documentation"/>
                </pre>
              </td>
            </tr>
          </xsl:for-each>

        </table>
      </td>
    </tr>


  </xsl:template>

</xsl:stylesheet>